package com.zzns.web.utils;

import org.springframework.web.servlet.ModelAndView;
import org.springframework.web.servlet.handler.HandlerInterceptorAdapter;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

/**
 * Date:15/6/1
 * Time:17:14
 * Author Mr.Object
 */

public class LoginInterceptor extends HandlerInterceptorAdapter{

    private final String mainURL="login.jsp";


    /**
     * 在业务处理器处理请求之前被调用
     * 如果返回false
     *     执行afterCompletion(),退出拦截器链
     * 如果返回true
     * 执行postHandle()
     *    接着再从最后一个拦截器往回执行所有的afterCompletion()
     */
    @Override
    public boolean preHandle(HttpServletRequest request, HttpServletResponse response, Object handler) throws Exception {
      /* boolean isOk=false;
        String url=request.getRequestURL().toString();

        if(url.contains(mainURL)){
            isOk=true;
        }else{
            HttpSession session=request.getSession();
            String username= (String) session.getAttribute("username");

            if(username==null){
                response.sendRedirect(request.getContextPath() + "/login");
                isOk=false;
            }

        }
        return isOk;*/
        return true;


    }

    @Override
    public void postHandle(HttpServletRequest request, HttpServletResponse response, Object handler, ModelAndView modelAndView) throws Exception {
     super.postHandle(request,response,handler,modelAndView);
    }



}
